package gameMap;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;

import javax.swing.*;

public class Map2 extends JLayeredPane{
	
	//public JLayeredPane layeredPane;
	public JLabel mapLabel;
	public JLabel smallMapLabel;
	int charPos = 0;

	public ImageIcon imagesMap2 = new ImageIcon("src/mansionMap2.png");
	public ImageIcon firstFloor = new ImageIcon("src/mansion1st.png");

	
	public ImageIcon[] iM = new ImageIcon[3];
	public JLabel[] jM = new JLabel [3];
	public ImageIcon[] grayM = new ImageIcon[3];
	public JLabel[] grayLabel = new JLabel[3];

	LinkedList<Integer> rV = new LinkedList<Integer>();
	
	public Map2(){
		super();
		rV.add(new Integer(0));
		//layeredPane = getLayeredPane();
		iM[0] = new ImageIcon("src/Layers/2ndFloor1.png");
		iM[1] = new ImageIcon("src/Layers/2ndFloor2.png");
		iM[2] = new ImageIcon("src/Layers/2ndFloor3.png");

		
		grayM[0] = new ImageIcon("src/Layers/2ndFloor1GRAY.png");
		grayM[1] = new ImageIcon("src/Layers/2ndFloor2GRAY.png");
		grayM[2] = new ImageIcon("src/Layers/2ndFloor3GRAY.png");

		
		for(int i = 0; i < iM.length; i++){
			jM[i] = new JLabel(iM[i]);
			jM[i].setBounds(0,0,640,455);
			jM[i].setLocation(0,0);
		}
		for(int i = 3; i < grayM.length; i++){
			grayLabel[i] = new JLabel(grayM[i]);
			grayLabel[i].setBounds(0,0,640,455);
			grayLabel[i].setLocation(0,0);
		}
		mapLabel = new JLabel(imagesMap2);
		mapLabel.setBounds(0,0,640,455);
		//firstButton.add(mapFirst);
		
		smallMapLabel = new JLabel(firstFloor);
		smallMapLabel.setBounds(0,0,160,167);
		smallMapLabel.setLocation(28,254);

		add(mapLabel, new Integer(0));
		add(smallMapLabel, new Integer(3));
		
//		mapSecond.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent event){
//				new Thread(new Runnable(){						
//					public void run(){
//						SwingUtilities.invokeLater(new Runnable(){
//							public void run(){
//								//layeredPane.remove(mapLabel);
//								//layeredPane.remove(mapSecond);
//								removeAll();
//								mapLabel.setIcon(imagesMap2);
//								add(mapLabel, new Integer(0));
//								add(mapFirst, new Integer(3));
//							}
//						});
//					}
//				}).start();
//			}		
//		});
//		mapFirst.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent event){
//				new Thread(new Runnable(){						
//					public void run(){
//						SwingUtilities.invokeLater(new Runnable(){
//							public void run(){
////								layeredPane.remove(mapLabel);
////								layeredPane.remove(mapFirst);
//								removeAll();
//								mapLabel.setIcon(imagesMap);
//								add(mapLabel, new Integer(0));
//								add(mapSecond, new Integer(3));
//								makeGray();
//								for(int a = 0; a < rV.size(); a++){
//									if(rV.get(a) != null){
//										add(jM[rV.get(a)], new Integer(4));
//									}
//								}
//							}
//						});
//					}
//				}).start();
//			}		
//		});
		
		addToList(1);
		//addToList(5);
		//addToList(8);
		//addToList(2);
		makeGray();
//		addToList(2);
//		addToList(8);
//		for(int j = 0; j < 12; j++){
//			layeredPane.add(jM[j], new Integer(4));
//		}
	}
	public void makeGray(){
		for(int i = 3; i < grayLabel.length; i++){
			add(grayLabel[i], new Integer(4));
		}
	}
	public void addToList(int roomValue){
		makeGray();
		rV.add(new Integer(roomValue));
		add(jM[roomValue], new Integer(4));
	}
	public ImageIcon showMap()
	{
		return imagesMap2;
	}
	public int showCharPos()
	{
		return charPos;
	}
} 
